<template>
  <div>
    <el-form 
      label-width="100px"
      label-position="top"
      :rules="rules"
      class="enterpriseForm"
      :model="webimSetData"
      ref="webimSetData">
      <h3 class="title">{{$t('configLazyLoad.visitorWaitConfig.enterprisePush')}}</h3>
      <el-form-item :label="$t('config.channel.AgentOfflineTipSet')" prop="weixinEnterpriseMsg">
        <el-input type="textarea" :rows="3" v-model="webimSetData.weixinEnterpriseMsg"></el-input>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark1')}}</p>
      </el-form-item>
      <el-form-item :label="$t('config.channel.openPushTip')" prop="setweixinEnterpriseWarnMsg">
        <el-radio-group v-model="webimSetData.setweixinEnterpriseWarnMsg">
          <el-radio class="radio" label="1" id="PushTipOn">{{$t('config.channel.enabled')}}</el-radio>
          <el-radio class="radio" label="0" id="PushTipOff">{{$t('config.channel.disabled')}}</el-radio>
        </el-radio-group>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark2')}}</p>
      </el-form-item>
      <el-form-item :label="$t('configLazyLoad.visitorWaitConfig.weixinWarnLen')" prop="weixinEnterpriseWarnLen" v-if="webimSetData.setweixinEnterpriseWarnMsg === '1'">
        <el-input v-model="webimSetData.weixinEnterpriseWarnLen">
          <template slot="append">{{$t('public.minutes2')}}</template>
        </el-input>
        <span class="remark">{{$t('configLazyLoad.visitorWaitConfig.default10Min')}}</span>
      </el-form-item>
      <el-form-item :label="$t('configLazyLoad.visitorWaitConfig.wechatRemark8')" prop="weixinEnterpriseWarnMsg" v-if="webimSetData.setweixinEnterpriseWarnMsg === '1'">
        <el-input type="textarea" :placeholder="$t('configLazyLoad.visitorWaitConfig.wechatRemark7')" v-model="webimSetData.weixinEnterpriseWarnMsg"></el-input>
      </el-form-item>
      <!-- <h3 class="title">{{$t('configLazyLoad.visitorWaitConfig.enterpriseLineUp')}}</h3> -->
      <el-form-item :label="$t('configLazyLoad.visitorWaitConfig.enterpriseTips')" prop="weixinEnterpriseQueueNumSwitch">
        <el-input type="textarea" :rows="3" :placeholder="$t('configLazyLoad.visitorWaitConfig.wechatRemark5')" v-model="webimSetData.weixinEnterpriseQueueNumSwitch"></el-input>
        <p class="remark">{{$t('configLazyLoad.visitorWaitConfig.wechatRemark4')}}</p>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" class="primary_btn fr" @click="saveFun">{{$t('public.save')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {checkform} from '@/utils/validate'
export default {
  name: 'enterpriseWebimSet',
  data () {
    let validateNum = (rule, value, callback) => {
      let message = checkform(value, 'Number3')
      if (message) {
        callback(new Error(this.$t(message)))
      } else {
        callback()
      }
    }
    return {
      webimSetData: {
        weixinEnterpriseMsg: '',
        setweixinEnterpriseWarnMsg: '1',
        weixinEnterpriseWarnLen: 10,
        weixinEnterpriseWarnMsg: '',
        weixinEnterpriseQueueNumSwitch: ''
      },
      rules: {
        weixinEnterpriseWarnLen: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'},
          {validator: validateNum, trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    saveFun () {
      this.$refs.webimSetData.validate((valid) => {
        if (valid) {
          if (this.webimSetData.setweixinEnterpriseWarnMsg === '1' && this.webimSetData.weixinEnterpriseWarnLen === '') {
            this.$message.error(this.$t('configLazyLoad.channel.enterpriseTip16'))
            return
          }
          this.$store.dispatch('saveGlobalSet', this.webimSetData).then((rep) => {
            if (rep.success) {
              this.$message.success(this.$t('config.channel.configSuccess'))
            } else {
              this.$message.error(this.$t('qualityCheck.saveFali'))
            }
          })
        }
      })
    }
  },
  beforeMount () {
    this.$store.dispatch('getGlobalSetById', {}).then((resp) => {
      if (resp.success && resp.row) {
        this.webimSetData._id = resp.row._id
        this.webimSetData.weixinEnterpriseMsg = resp.row.weixinEnterpriseMsg || ''
        this.webimSetData.setweixinEnterpriseWarnMsg = resp.row.setweixinEnterpriseWarnMsg || '1'
        this.webimSetData.weixinEnterpriseWarnLen = resp.row.weixinEnterpriseWarnLen || '10'
        this.webimSetData.weixinEnterpriseWarnMsg = resp.row.weixinEnterpriseWarnMsg || ''
        this.webimSetData.weixinEnterpriseQueueNumSwitch = resp.row.weixinEnterpriseQueueNumSwitch || ''
      }
    })
  }
}
</script>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
    .enterpriseForm
      width 500px
      .title
        font-weight 900
        margin-bottom 5px
      .remark
        color: #888888
        font-size 12px
        margin-top 10px
</style>